using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX.Direct3D;
using Microsoft.DirectX;
using System.Drawing;

namespace Boids2D
{
    class DXPanel : Panel
    {
        private Device device;

        public Device Device
        {
            get { return device; }
            set { device = value; }
        }
        List<Mesh> meshList;

        internal List<Mesh> MeshList
        {
            get { return meshList; }
            set { meshList = value; }
        }

        public DXPanel()
        {
            meshList = new List<Mesh>();

        }


        public void InitializeDevice()
        {
            PresentParameters presentParams = new PresentParameters();
            presentParams.Windowed = true;
            presentParams.SwapEffect = SwapEffect.Discard;

            device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
            device.VertexFormat = CustomVertex.TransformedColored.Format;
            this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);
        }


        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            device.Clear(ClearFlags.Target, Color.White, 1.0f, 0);
            /*
            
           
            foreach (Mesh mesh in meshList)
            {
                foreach (Triangle tri in mesh.Triangles)
                {
                    device.BeginScene();
                    device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, tri.Vertices);
                    device.EndScene();
                }
            }
            
            device.Present();
            //this.Invalidate();
            */
        }

    }
}
